/*
 * Copyright (C) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the 'License');
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an 'AS IS' BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


#ifndef IMAGE_KNIFE_C_KEKE_IMAGEKNIFE_DECODER_AVIF_H
#define IMAGE_KNIFE_C_KEKE_IMAGEKNIFE_DECODER_AVIF_H

#include "imageknife_type.h"
#include <memory>
#include <multimedia/image_framework/image/pixelmap_native.h>

#ifdef IMAGE_KNIFE_ENABLE_AVIF_DECODER
#include "avif/avif.h"
#endif

namespace ImageKnifePro {

class ImageKnifeDecoderAvif {
public:
    static bool IsAvifEnable();

    ImageKnifeDecoderAvif();
    ~ImageKnifeDecoderAvif();

    // 解析图片的原始宽度
    uint32_t GetWidth() const;
    // 解析图片的原始高度
    uint32_t GetHeight() const;
    uint32_t GetFrameCount() const;
    std::shared_ptr<int []> GetDelayTimeList() const;

    std::string Init(uint8_t *buffer, uint32_t length);
    std::string DecodeFrame(uint32_t frameIndex, OH_PixelmapNative **pixelmapOut);

    void SetAllocationMode(AllocationMode mode);
    void SetDesiredImageSize(Image_Size imageSize);
private:
    std::string CreatePixelmapNative(OH_PixelmapNative **pixelmapOut);

    std::shared_ptr<int []> delayTimeList_ = nullptr;
    IMAGE_ALLOCATOR_MODE allocationMode_ = IMAGE_ALLOCATOR_MODE_AUTO;
    uint32_t desiredWidth_ = 0;
    uint32_t desiredHeight_ = 0;

#ifdef IMAGE_KNIFE_ENABLE_AVIF_DECODER
    avifDecoder *decoder_ = nullptr;
    avifRGBImage rgbImage_;
#endif
};

}

#endif //IMAGE_KNIFE_C_KEKE_IMAGEKNIFE_DECODER_AVIF_H
